package link.cocoon.common.resp;

import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.Collection;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author xce
 * @date 2020/4/7  10:59
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RespPage<T> implements Resp {

  private int code;
  private String message;
  private Collection<T> data;
  private PageInfo pageInfo;




  public static RespPage success(IPage page) {
    return success(page, "成功");
  }

  public static RespPage success(IPage page, String message) {
    PageInfo pageInfo = new PageInfo();
    RespPage respPage = new RespPage();
    respPage.setCode(respPage.getSuccessCode());
    respPage.setMessage(message);
    respPage.setData(page.getRecords());
    pageInfo.setCurrent(page.getCurrent());
    pageInfo.setTotal(page.getTotal());
    pageInfo.setSize(page.getSize());
    respPage.setPageInfo(pageInfo);
    return respPage;
  }


}
